package com.kongmou.springSecurity.security;

import com.kongmou.springSecurity.dao.UserDetailsRepository;
import com.kongmou.springSecurity.domain.SysUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;

public class CustomUserService implements UserDetailsService{//自定义实现UserDetailsServices接口

    @Resource
    UserDetailsRepository userDetailsRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {//重写loadUserByusername 方法获得用户

        SysUser user = userDetailsRepository.getByUsername(username);
        if(null == user){
            throw new RuntimeException("不存在此用户");
        }
        return user;//
    }
}
